package view.dlct.donvikiemtoanvien.backing;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;

import java.sql.SQLException;
import java.sql.Timestamp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import java.util.TimeZone;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectItems;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.view.rich.component.rich.RichDialog;
import oracle.adf.view.rich.component.rich.RichPopup;
import oracle.adf.view.rich.component.rich.data.RichColumn;
import oracle.adf.view.rich.component.rich.data.RichTable;
import oracle.adf.view.rich.component.rich.input.RichInputDate;
import oracle.adf.view.rich.component.rich.input.RichInputFile;
import oracle.adf.view.rich.component.rich.input.RichInputText;
import oracle.adf.view.rich.component.rich.input.RichSelectOneChoice;
import oracle.adf.view.rich.component.rich.input.RichTextEditor;
import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelGroupLayout;
import oracle.adf.view.rich.component.rich.layout.RichPanelTabbed;
import oracle.adf.view.rich.component.rich.layout.RichShowDetailItem;
import oracle.adf.view.rich.component.rich.nav.RichCommandButton;
import oracle.adf.view.rich.component.rich.nav.RichCommandToolbarButton;
import oracle.adf.view.rich.component.rich.output.RichOutputText;
import oracle.adf.view.rich.context.AdfFacesContext;
import oracle.adf.view.rich.event.DialogEvent;
import oracle.adf.view.rich.event.PopupCanceledEvent;

import oracle.jbo.Key;
import oracle.jbo.NameValuePairs;
import oracle.jbo.Row;
import oracle.jbo.RowSet;
import oracle.jbo.domain.BlobDomain;
import oracle.jbo.domain.ClobDomain;
import oracle.jbo.domain.DBSequence;
import oracle.jbo.domain.Number;

import org.apache.myfaces.trinidad.component.UIXInput;
import org.apache.myfaces.trinidad.event.SelectionEvent;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.RowKeySetImpl;
import org.apache.myfaces.trinidad.model.UploadedFile;
import org.apache.myfaces.trinidadinternal.taglib.util.MethodExpressionMethodBinding;

import view.common.Utils;
import view.common.search.AdvancedSearchGroup;
import view.common.search.AdvancedSearchItem;


public class DonViKiemToanVienBean {
    private RichPanelFormLayout searchPanel = new RichPanelFormLayout();
    private RichPanelFormLayout searchKtvPanel = new RichPanelFormLayout();
    private RichTable tableVaoRaDonVi = new RichTable();
    private RichTable tableKtv = new RichTable();
    private RichPopup popupUpdate = new RichPopup();
    private RichDialog dialogUpdate = new RichDialog();
    private RichPopup popupDelete = new RichPopup();
    private RichPanelTabbed updatePanel = new RichPanelTabbed();
    private final String SEARCH_ID_PREFIX = "search";
    private final String SEARCH_KTV_ID_PREFIX = "searchktv";
    private final String UPDATE_ID_PREFIX = "update";
    private final String ROW_KEY = "rowkey";
    private final String FILE_GROUP_ID_SUBFIX = "group";
    private final String FILE_LABEL_ID_SUBFIX = "label";
    private final String FILE_REMOVE_ID_SUBFIX = "remove";
    private final String DEFAULT_LANGCODE="vi";
    private RichSelectOneChoice goToPage = new RichSelectOneChoice();
    private RichCommandToolbarButton firstPage =
        new RichCommandToolbarButton();
    private RichCommandToolbarButton prevPage = new RichCommandToolbarButton();
    private RichCommandToolbarButton nextPage = new RichCommandToolbarButton();
    private RichCommandToolbarButton lastPage = new RichCommandToolbarButton();
    private RichSelectOneChoice goToPageKtv = new RichSelectOneChoice();
    private RichCommandToolbarButton firstPageKtv =
        new RichCommandToolbarButton();
    private RichCommandToolbarButton prevPageKtv =
        new RichCommandToolbarButton();
    private RichCommandToolbarButton nextPageKtv =
        new RichCommandToolbarButton();
    private RichCommandToolbarButton lastPageKtv =
        new RichCommandToolbarButton();
    private RichOutputText tenDonVi;

    public DonViKiemToanVienBean() {
    }

    public void beforePhase(PhaseEvent phaseEvent) {
        if (Boolean.FALSE.equals(Utils.getElExpression("#{adfFacesContext.postback}"))) {
            Utils.search("DlctKtvDvView1Iterator", new ArrayList());
            resetForm();
            getValue(0);
            rollback(null);
        }
    }

    private void resetForm() {
        searchPanel.getChildren().clear();
        tableVaoRaDonVi.getChildren().clear();
        List<AdvancedSearchGroup> listASG = new ArrayList();
        AdvancedSearchGroup asg = new AdvancedSearchGroup();
        listASG.add(asg);
        AdvancedSearchItem asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("DlctLoaiTruongTt");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_LOAI_TRUONG_TT.KIEM_TOAN_VIEN.getId()));
        asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("TrangThai");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
        DCIteratorBinding truongTtView1Iterator =
            Utils.getIteratorBinding("DlctTruongTtView1Iterator");
        truongTtView1Iterator.setRangeSize(-1);
        Row[] rows = truongTtView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        for (int i = 0; i < rows.length; i++) {
            String id = ((DBSequence)rows[i].getAttribute("Id")).toString();
            String ten = (String)rows[i].getAttribute("TenTruong");
            Number kieuDuLieu = (Number)rows[i].getAttribute("KieuDuLieu");
            Number viTriHienThi = (Number)rows[i].getAttribute("ViTriHienThi");
            if (viTriHienThi != null && kieuDuLieu != null) {
                int viTri = viTriHienThi.intValue();
                int kieu = kieuDuLieu.intValue();
                if ((Utils.ENUM_VI_TRI_HIEN_THI.SEARCH.getId() & viTri) ==
                    Utils.ENUM_VI_TRI_HIEN_THI.SEARCH.getId()) {
                    List<UIComponent> components =
                        createSearchComponent(SEARCH_ID_PREFIX +
                                              rows[i].getKey().toStringFormat(false),
                                              ten, kieu);
                    if (components != null) {
                        searchPanel.getChildren().addAll(components);
                    }
                }
                if ((Utils.ENUM_VI_TRI_HIEN_THI.TABLE.getId() & viTri) ==
                    Utils.ENUM_VI_TRI_HIEN_THI.TABLE.getId()) {
                    UIComponent component = createColumn(id, ten,kieu);
                    if (component != null) {
                        tableVaoRaDonVi.getChildren().add(component);
                    }
                }
            }
        }
        {
            FacesContext fc = FacesContext.getCurrentInstance();
            Application app = fc.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = fc.getELContext();
            ValueExpression valueExp;
            RichColumn column = new RichColumn();
            column.setHeaderText("Ngày bắt đầu");
            DateTimeConverter converter = (DateTimeConverter)FacesContext.getCurrentInstance().getApplication()
            .createConverter("javax.faces.DateTime");
            converter.setLocale(new Locale(DEFAULT_LANGCODE));
            converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
            converter.setType("date");
            converter.setDateStyle("short");
            RichOutputText outputText = new RichOutputText();
            outputText.setConverter(converter);
            valueExp =
                    elFactory.createValueExpression(elContext, "#{row['NgayBatDau']}",
                                                    Object.class);
            outputText.setValueExpression("value", valueExp);
            column.getChildren().add(outputText);
            tableVaoRaDonVi.getChildren().add(column);
            column = new RichColumn();
            column.setHeaderText("Ngày kết thúc");
            outputText = new RichOutputText();
            outputText.setConverter(converter);
            valueExp =
                    elFactory.createValueExpression(elContext, "#{row['NgayKetThuc']}",
                                                    Object.class);
            outputText.setValueExpression("value", valueExp);
            column.getChildren().add(outputText);
            tableVaoRaDonVi.getChildren().add(column);
        }
        if (searchPanel.getChildren().size() > 0) {
            FacesContext fc = FacesContext.getCurrentInstance();
            Application app = fc.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = fc.getELContext();
            MethodExpression methodExpression =
                elFactory.createMethodExpression(elContext,
                                                 "#{donViKiemToanVienBean.timKiem}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
            ValueExpression valueExp =
                elFactory.createValueExpression(elContext,
                                                "#{adfBundle['view.ViewControllerBundle'].TIM_KIEM}",
                                                Object.class);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            RichCommandButton buttonSearch = new RichCommandButton();
            buttonSearch.setId("searchButton");
            buttonSearch.setValueExpression("text", valueExp);
            buttonSearch.setInlineStyle("margin-bottom:10px;");
            buttonSearch.getAttributes().put("actionListener",
                                             methodExpressionMethodBinding);
            searchPanel.getChildren().add(buttonSearch);
        }
        DCIteratorBinding donViView1Iterator =
            Utils.getIteratorBinding("DlctDonViView1Iterator");
        RowSet gtDvTtRowSet =
            (RowSet)donViView1Iterator.getCurrentRow().getAttribute("DlctGtDvTtView");
        String ten = "";
        if (gtDvTtRowSet != null) {
            gtDvTtRowSet.setRangeSize(-1);
            Row[] gtDvTtRows = gtDvTtRowSet.getAllRowsInRange();
            if (gtDvTtRows == null) {
                gtDvTtRows = new Row[] { };
            }
            for (int k = 0; k < gtDvTtRows.length; k++) {
                Row gtDvTtTruongTtRow =
                    (Row)gtDvTtRows[k].getAttribute("DlctTruongTtView");
                Number gtDvTtKieuDuLieu =
                    (Number)gtDvTtTruongTtRow.getAttribute("KieuDuLieu");
                Number gtDvTtViTriHienThi =
                    (Number)gtDvTtTruongTtRow.getAttribute("ViTriHienThi");
                if (gtDvTtViTriHienThi != null &&
                    gtDvTtKieuDuLieu != null) {
                    int gtDvViTri = gtDvTtViTriHienThi.intValue();
                    int gtDvKieu = gtDvTtKieuDuLieu.intValue();
                    if ((Utils.ENUM_VI_TRI_HIEN_THI.SELECT.getId() &
                         gtDvViTri) ==
                        Utils.ENUM_VI_TRI_HIEN_THI.SELECT.getId()) {
                        if (gtDvKieu ==
                            Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                            Number valNumber =
                                (Number)gtDvTtRows[k].getAttribute("ValNumber");
                            if (valNumber != null) {
                                ten = ten + valNumber.toString() + " ";
                            }
                        }
                        if (gtDvKieu ==
                            Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                            String valVarchar =
                                (String)gtDvTtRows[k].getAttribute("ValVarchar");
                            if (valVarchar != null) {
                                ten = ten + valVarchar + " ";
                            }
                        }
                    }
                }
            }
        }
        tenDonVi.setValue(ten);
    }

    private void resetFormKtv() {
        searchKtvPanel.getChildren().clear();
        tableKtv.getChildren().clear();
        List<AdvancedSearchGroup> listASG = new ArrayList();
        AdvancedSearchGroup asg = new AdvancedSearchGroup();
        listASG.add(asg);
        AdvancedSearchItem asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("DlctLoaiTruongTt");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_LOAI_TRUONG_TT.KIEM_TOAN_VIEN.getId()));
        asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("TrangThai");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
        DCIteratorBinding truongTtView1Iterator =
            Utils.getIteratorBinding("DlctTruongTtView1Iterator");
        truongTtView1Iterator.setRangeSize(-1);
        Row[] rows = truongTtView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        for (int i = 0; i < rows.length; i++) {
            String id = ((DBSequence)rows[i].getAttribute("Id")).toString();
            String ten = (String)rows[i].getAttribute("TenTruong");
            Number kieuDuLieu = (Number)rows[i].getAttribute("KieuDuLieu");
            Number viTriHienThi = (Number)rows[i].getAttribute("ViTriHienThi");
            if (viTriHienThi != null && kieuDuLieu != null) {
                int viTri = viTriHienThi.intValue();
                int kieu = kieuDuLieu.intValue();
                if ((Utils.ENUM_VI_TRI_HIEN_THI.SEARCH.getId() & viTri) ==
                    Utils.ENUM_VI_TRI_HIEN_THI.SEARCH.getId()) {
                    List<UIComponent> components =
                        createSearchComponent(SEARCH_KTV_ID_PREFIX +
                                              rows[i].getKey().toStringFormat(false),
                                              ten, kieu);
                    if (components != null) {
                        searchKtvPanel.getChildren().addAll(components);
                    }
                }
                if ((Utils.ENUM_VI_TRI_HIEN_THI.TABLE.getId() & viTri) ==
                    Utils.ENUM_VI_TRI_HIEN_THI.TABLE.getId()) {
                    UIComponent component = createColumn(id, ten,kieu);
                    if (component != null) {
                        tableKtv.getChildren().add(component);
                    }
                }
            }
        }
        if (searchKtvPanel.getChildren().size() > 0) {
            FacesContext fc = FacesContext.getCurrentInstance();
            Application app = fc.getApplication();
            ExpressionFactory elFactory = app.getExpressionFactory();
            ELContext elContext = fc.getELContext();
            MethodExpression methodExpression =
                elFactory.createMethodExpression(elContext,
                                                 "#{donViKiemToanVienBean.timKiemKtv}",
                                                 null,
                                                 new Class[] { ActionEvent.class });
            ValueExpression valueExp =
                elFactory.createValueExpression(elContext,
                                                "#{adfBundle['view.ViewControllerBundle'].TIM_KIEM}",
                                                Object.class);
            MethodExpressionMethodBinding methodExpressionMethodBinding =
                new MethodExpressionMethodBinding(methodExpression);
            RichCommandButton buttonSearch = new RichCommandButton();
            buttonSearch.setPartialSubmit(true);
            buttonSearch.setImmediate(true);
            buttonSearch.setId("searchButtonKtv");
            buttonSearch.setValueExpression("text", valueExp);
            buttonSearch.setInlineStyle("margin-bottom:10px;");
            buttonSearch.getAttributes().put("actionListener",
                                             methodExpressionMethodBinding);
            searchKtvPanel.getChildren().add(buttonSearch);
        }
    }

    private void getValue(int pageNum) {
        resetPaging("DlctKtvDvView1Iterator", pageNum);
        DCIteratorBinding ktvDvView1Iterator =
            Utils.getIteratorBinding("DlctKtvDvView1Iterator");
        List<HashMap<String, Object>> listValue = new ArrayList();
        Row[] rows = ktvDvView1Iterator.getAllRowsInRange();
        String currentRowKey = "";
        if (ktvDvView1Iterator.getCurrentRow() != null &&
            ktvDvView1Iterator.getCurrentRowIndexInRange() >= 0 &&
            ktvDvView1Iterator.getCurrentRowIndexInRange() <
            ktvDvView1Iterator.getRangeSize()) {
            currentRowKey =
                    ktvDvView1Iterator.getCurrentRow().getKey().toStringFormat(false);
        }
        RowKeySet rowKeySet = tableVaoRaDonVi.getSelectedRowKeys();
        if (rowKeySet == null) {
            rowKeySet = new RowKeySetImpl();
            tableVaoRaDonVi.setSelectedRowKeys(rowKeySet);
        }
        rowKeySet.removeAll();
        for (int i = 0; i < rows.length; i++) {
            ktvDvView1Iterator.setCurrentRowIndexInRange(i);
            String rowKey =
                ktvDvView1Iterator.getCurrentRow().getKey().toStringFormat(false);
            if (currentRowKey == null || currentRowKey.isEmpty()) {
                currentRowKey = rowKey;
            }
            if (currentRowKey.equals(rowKey)) {
                rowKeySet.add(i);
            }
            Row kiemToanVienRow =
                (Row)ktvDvView1Iterator.getCurrentRow().getAttribute("DlctKiemToanVienView");
            if (kiemToanVienRow != null) {
                RowSet rowSetGtTt =
                    (RowSet)kiemToanVienRow.getAttribute("DlctGtKtvTtView");
                if (rowSetGtTt != null) {
                    rowSetGtTt.setRangeSize(-1);
                    Row[] rowsGtTt = rowSetGtTt.getAllRowsInRange();
                    if (rowsGtTt == null) {
                        rowsGtTt = new Row[] { };
                    }
                    HashMap<String, Object> mapValue = new HashMap();
                    mapValue.put(ROW_KEY, rowKey);
                    {
                        oracle.jbo.domain.Date valDate =
                            (oracle.jbo.domain.Date)ktvDvView1Iterator.getCurrentRow().getAttribute("NgayBatDau");
                        if (valDate != null) {
                            java.util.Date date = valDate.dateValue();
                            if (date != null) {
                                mapValue.put("NgayBatDau", date);
                            }
                        }
                    }
                    {
                        oracle.jbo.domain.Date valDate =
                            (oracle.jbo.domain.Date)ktvDvView1Iterator.getCurrentRow().getAttribute("NgayKetThuc");
                        if (valDate != null) {
                            java.util.Date date = valDate.dateValue();
                            if (date != null) {
                                mapValue.put("NgayKetThuc", date);
                            }
                        }
                    }
                    for (int j = 0; j < rowsGtTt.length; j++) {
                        Row truongTtRow =
                            (Row)rowsGtTt[j].getAttribute("DlctTruongTtView");
                        if (truongTtRow != null) {
                            Number id =
                                ((DBSequence)truongTtRow.getAttribute("Id")).getSequenceNumber();
                            Number kieuDuLieu =
                                (Number)truongTtRow.getAttribute("KieuDuLieu");
                            if (id != null && kieuDuLieu != null) {
                                int kieu = kieuDuLieu.intValue();
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                    Number valNumber =
                                        (Number)rowsGtTt[j].getAttribute("ValNumber");
                                    if (valNumber != null) {
                                        mapValue.put(id.toString(),
                                                     valNumber.toString());
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                    String valVarchar =
                                        (String)rowsGtTt[j].getAttribute("ValVarchar");
                                    if (valVarchar != null) {
                                        mapValue.put(id.toString(),
                                                     valVarchar);
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                    String valVarchar =
                                        (String)rowsGtTt[j].getAttribute("ValVarchar");
                                    if (valVarchar != null) {
                                        mapValue.put(id.toString(),
                                                     valVarchar);
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                    String valVarchar =
                                        (String)rowsGtTt[j].getAttribute("ValVarchar");
                                    if (valVarchar != null) {
                                        mapValue.put(id.toString(),
                                                     valVarchar);
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                    oracle.jbo.domain.Date valDate =
                                        (oracle.jbo.domain.Date)rowsGtTt[j].getAttribute("ValDate");
                                    if (valDate != null) {
                                        java.util.Date date =
                                            valDate.dateValue();
                                        if (date != null) {
                                            mapValue.put(id.toString(), date);
                                        }
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                    ClobDomain valClob =
                                        (ClobDomain)rowsGtTt[j].getAttribute("ValClob");
                                    if (valClob != null) {
                                        mapValue.put(id.toString(),
                                                     valClob.toString());
                                    }
                                }
                                if (kieu ==
                                    Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                    Row fileViewRow =
                                        (Row)rowsGtTt[j].getAttribute("HtFileView");
                                    if (fileViewRow != null) {
                                        String tenFile =
                                            (String)fileViewRow.getAttribute("TenFile");
                                        if (tenFile != null) {
                                            mapValue.put(id.toString(),
                                                         tenFile);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    listValue.add(mapValue);
                }
            }
        }
        if (currentRowKey != null && currentRowKey.isEmpty() == false) {
            ktvDvView1Iterator.setCurrentRowWithKey(currentRowKey);
        }
        tableVaoRaDonVi.setValue(listValue);
    }

    private void getValueKtv(int pageNum) {
        resetPagingKtv("DlctKiemToanVienView1Iterator", pageNum);
        DCIteratorBinding kiemToanVienView1Iterator =
            Utils.getIteratorBinding("DlctKiemToanVienView1Iterator");
        List<HashMap<String, Object>> listValue = new ArrayList();
        Row[] rows = kiemToanVienView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        String currentRowKey = "";
        if (kiemToanVienView1Iterator.getCurrentRow() != null &&
            kiemToanVienView1Iterator.getCurrentRowIndexInRange() >= 0 &&
            kiemToanVienView1Iterator.getCurrentRowIndexInRange() <
            kiemToanVienView1Iterator.getRangeSize()) {
            currentRowKey =
                    kiemToanVienView1Iterator.getCurrentRow().getKey().toStringFormat(false);
        }
        RowKeySet rowKeySet = tableKtv.getSelectedRowKeys();
        if (rowKeySet == null) {
            rowKeySet = new RowKeySetImpl();
            tableKtv.setSelectedRowKeys(rowKeySet);
        }
        rowKeySet.removeAll();
        for (int i = 0; i < rows.length; i++) {
            kiemToanVienView1Iterator.setCurrentRowIndexInRange(i);
            String rowKey =
                kiemToanVienView1Iterator.getCurrentRow().getKey().toStringFormat(false);
            if (currentRowKey == null || currentRowKey.isEmpty()) {
                currentRowKey = rowKey;
            }
            if (currentRowKey.equals(rowKey)) {
                rowKeySet.add(i);
            }
            RowSet rowSetGtTt =
                (RowSet)kiemToanVienView1Iterator.getCurrentRow().getAttribute("DlctGtKtvTtView");
            if (rowSetGtTt != null) {
                rowSetGtTt.setRangeSize(-1);
                Row[] rowsGtTt = rowSetGtTt.getAllRowsInRange();
                if (rowsGtTt == null) {
                    rowsGtTt = new Row[] { };
                }
                HashMap<String, Object> mapValue = new HashMap();
                mapValue.put(ROW_KEY, rowKey);
                for (int j = 0; j < rowsGtTt.length; j++) {
                    Row truongTtRow =
                        (Row)rowsGtTt[j].getAttribute("DlctTruongTtView");
                    if (truongTtRow != null) {
                        Number id =
                            ((DBSequence)truongTtRow.getAttribute("Id")).getSequenceNumber();
                        Number kieuDuLieu =
                            (Number)truongTtRow.getAttribute("KieuDuLieu");
                        if (id != null && kieuDuLieu != null) {
                            int kieu = kieuDuLieu.intValue();
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                Number valNumber =
                                    (Number)rowsGtTt[j].getAttribute("ValNumber");
                                if (valNumber != null) {
                                    mapValue.put(id.toString(),
                                                 valNumber.toString());
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                oracle.jbo.domain.Date valDate =
                                    (oracle.jbo.domain.Date)rowsGtTt[j].getAttribute("ValDate");
                                if (valDate != null) {
                                    java.util.Date date = valDate.dateValue();
                                    if (date != null) {
                                        mapValue.put(id.toString(), date);
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                ClobDomain valClob =
                                    (ClobDomain)rowsGtTt[j].getAttribute("ValClob");
                                if (valClob != null) {
                                    mapValue.put(id.toString(),
                                                 valClob.toString());
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                Row fileViewRow =
                                    (Row)rowsGtTt[j].getAttribute("HtFileView");
                                if (fileViewRow != null) {
                                    String tenFile =
                                        (String)fileViewRow.getAttribute("TenFile");
                                    if (tenFile != null) {
                                        mapValue.put(id.toString(), tenFile);
                                    }
                                }
                            }
                        }
                    }
                }
                listValue.add(mapValue);
            }
        }
        if (currentRowKey != null && currentRowKey.isEmpty() == false) {
            kiemToanVienView1Iterator.setCurrentRowWithKey(currentRowKey);
        }
        tableKtv.setValue(listValue);
    }

    private void getValueKtv() {
        resetPagingKtv("DlctKiemToanVienView1Iterator");
        DCIteratorBinding kiemToanVienView1Iterator =
            Utils.getIteratorBinding("DlctKiemToanVienView1Iterator");
        List<HashMap<String, Object>> listValue = new ArrayList();
        Row[] rows = kiemToanVienView1Iterator.getAllRowsInRange();
        if (rows == null) {
            rows = new Row[] { };
        }
        String currentRowKey = "";
        if (kiemToanVienView1Iterator.getCurrentRow() != null &&
            kiemToanVienView1Iterator.getCurrentRowIndexInRange() >= 0 &&
            kiemToanVienView1Iterator.getCurrentRowIndexInRange() <
            kiemToanVienView1Iterator.getRangeSize()) {
            currentRowKey =
                    kiemToanVienView1Iterator.getCurrentRow().getKey().toStringFormat(false);
        }
        RowKeySet rowKeySet = tableKtv.getSelectedRowKeys();
        if (rowKeySet == null) {
            rowKeySet = new RowKeySetImpl();
            tableKtv.setSelectedRowKeys(rowKeySet);
        }
        rowKeySet.removeAll();
        for (int i = 0; i < rows.length; i++) {
            kiemToanVienView1Iterator.setCurrentRowIndexInRange(i);
            String rowKey =
                kiemToanVienView1Iterator.getCurrentRow().getKey().toStringFormat(false);
            if (currentRowKey == null || currentRowKey.isEmpty()) {
                currentRowKey = rowKey;
            }
            if (currentRowKey.equals(rowKey)) {
                rowKeySet.add(i);
            }
            RowSet rowSetGtTt =
                (RowSet)kiemToanVienView1Iterator.getCurrentRow().getAttribute("DlctGtKtvTtView");
            if (rowSetGtTt != null) {
                rowSetGtTt.setRangeSize(-1);
                Row[] rowsGtTt = rowSetGtTt.getAllRowsInRange();
                if (rowsGtTt == null) {
                    rowsGtTt = new Row[] { };
                }
                HashMap<String, Object> mapValue = new HashMap();
                mapValue.put(ROW_KEY, rowKey);
                for (int j = 0; j < rowsGtTt.length; j++) {
                    Row truongTtRow =
                        (Row)rowsGtTt[j].getAttribute("DlctTruongTtView");
                    if (truongTtRow != null) {
                        Number id =
                            ((DBSequence)truongTtRow.getAttribute("Id")).getSequenceNumber();
                        Number kieuDuLieu =
                            (Number)truongTtRow.getAttribute("KieuDuLieu");
                        if (id != null && kieuDuLieu != null) {
                            int kieu = kieuDuLieu.intValue();
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                Number valNumber =
                                    (Number)rowsGtTt[j].getAttribute("ValNumber");
                                if (valNumber != null) {
                                    mapValue.put(id.toString(),
                                                 valNumber.toString());
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                String valVarchar =
                                    (String)rowsGtTt[j].getAttribute("ValVarchar");
                                if (valVarchar != null) {
                                    mapValue.put(id.toString(), valVarchar);
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                oracle.jbo.domain.Date valDate =
                                    (oracle.jbo.domain.Date)rowsGtTt[j].getAttribute("ValDate");
                                if (valDate != null) {
                                    java.util.Date date = valDate.dateValue();
                                    if (date != null) {
                                        mapValue.put(id.toString(), date);
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                ClobDomain valClob =
                                    (ClobDomain)rowsGtTt[j].getAttribute("ValClob");
                                if (valClob != null) {
                                    mapValue.put(id.toString(),
                                                 valClob.toString());
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                Row fileViewRow =
                                    (Row)rowsGtTt[j].getAttribute("HtFileView");
                                if (fileViewRow != null) {
                                    String tenFile =
                                        (String)fileViewRow.getAttribute("TenFile");
                                    if (tenFile != null) {
                                        mapValue.put(id.toString(), tenFile);
                                    }
                                }
                            }
                        }
                    }
                }
                listValue.add(mapValue);
            }
        }
        if (currentRowKey != null && currentRowKey.isEmpty() == false) {
            kiemToanVienView1Iterator.setCurrentRowWithKey(currentRowKey);
        }
        tableKtv.setValue(listValue);
    }

    private void resetPaging(String iteratorName, int pageNum) {
        DCIteratorBinding iterator = Utils.getIteratorBinding(iteratorName);
        int rowCount = (int)iterator.getEstimatedRowCount();
        int pageSize = Utils.getPageSize("HtCauHinhView1Iterator");
        int pageCount = 1;
        if (rowCount > pageSize) {
            if (rowCount % pageSize == 0) {
                pageCount = rowCount / pageSize;
            } else {
                pageCount = rowCount / pageSize + 1;
            }
        }

        if (pageNum < 1) {
            pageNum = 1;
        }
        if (pageNum > pageCount) {
            pageNum = pageCount;
        }
        if (pageNum == 1) {
            firstPage.setDisabled(true);
            prevPage.setDisabled(true);
        } else {
            firstPage.setDisabled(false);
            prevPage.setDisabled(false);
        }
        if (pageNum == pageCount) {
            lastPage.setDisabled(true);
            nextPage.setDisabled(true);
        } else {
            lastPage.setDisabled(false);
            nextPage.setDisabled(false);
        }
        int first = 1;
        if (pageNum < 5) {
            first = 1;
        } else if (pageNum + 9 > pageCount) {
            if (pageNum + 4 > pageCount) {
                if (pageCount - 6 < 1)
                    first = 1;
                else {
                    first = pageCount - 6;
                }
            } else {
                if (pageCount < 10) {
                    first = 1;
                } else {
                    first = pageNum - 4;
                }
            }
        } else {
            first = pageNum - 4;
        }
        List<SelectItem> listSelectItem = new ArrayList();

        for (int i = first, j = 0; i <= pageCount && j < 10; i++, j++) {
            SelectItem si = new SelectItem();
            si.setValue(""+i);
            si.setLabel(String.valueOf(i));
            listSelectItem.add(si);
        }
        UISelectItems uiSelectItems = new UISelectItems();
        uiSelectItems.setValue(listSelectItem);
        goToPage.setValue(""+pageNum);
        goToPage.getChildren().clear();
        goToPage.getChildren().add(uiSelectItems);
        goToPage.setValuePassThru(true);
        goToPage.setAutoSubmit(true);
        Row currentRow = iterator.getCurrentRow();
        iterator.executeQuery();
        if (currentRow != null) {
            iterator.setCurrentRowWithKey(currentRow.getKey().toStringFormat(false));
        }
        if ((pageNum) * pageSize > rowCount) {
            iterator.setRangeSize(rowCount - (pageNum - 1) * pageSize);
        } else {
            iterator.setRangeSize(pageSize);
        }
        iterator.setRangeStart((pageNum - 1) * pageSize);

        AdfFacesContext.getCurrentInstance().addPartialTarget(firstPage);
        AdfFacesContext.getCurrentInstance().addPartialTarget(prevPage);
        AdfFacesContext.getCurrentInstance().addPartialTarget(nextPage);
        AdfFacesContext.getCurrentInstance().addPartialTarget(lastPage);
        AdfFacesContext.getCurrentInstance().addPartialTarget(goToPage);
    }

    private void resetPagingKtv(String iteratorName, int pageNum) {
        DCIteratorBinding iterator = Utils.getIteratorBinding(iteratorName);
        int rowCount = (int)iterator.getEstimatedRowCount();
        int pageSize = Utils.getPageSize("HtCauHinhView1Iterator");
        int pageCount = 1;
        if (rowCount > pageSize) {
            if (rowCount % pageSize == 0) {
                pageCount = rowCount / pageSize;
            } else {
                pageCount = rowCount / pageSize + 1;
            }
        }

        if (pageNum < 1) {
            pageNum = 1;
        }
        if (pageNum > pageCount) {
            pageNum = pageCount;
        }
        if (pageNum == 1) {
            firstPageKtv.setDisabled(true);
            prevPageKtv.setDisabled(true);
        } else {
            firstPageKtv.setDisabled(false);
            prevPageKtv.setDisabled(false);
        }
        if (pageNum == pageCount) {
            lastPageKtv.setDisabled(true);
            nextPageKtv.setDisabled(true);
        } else {
            lastPageKtv.setDisabled(false);
            nextPageKtv.setDisabled(false);
        }
        int first = 1;
        if (pageNum < 5) {
            first = 1;
        } else if (pageNum + 9 > pageCount) {
            if (pageNum + 4 > pageCount) {
                if (pageCount - 6 < 1)
                    first = 1;
                else {
                    first = pageCount - 6;
                }
            } else {
                if (pageCount < 10) {
                    first = 1;
                } else {
                    first = pageNum - 4;
                }
            }
        } else {
            first = pageNum - 4;
        }
        List<SelectItem> listSelectItem = new ArrayList();

        for (int i = first, j = 0; i <= pageCount && j < 10; i++, j++) {
            SelectItem si = new SelectItem();
            si.setValue(""+i);
            si.setLabel(String.valueOf(i));
            listSelectItem.add(si);
        }
        UISelectItems uiSelectItems = new UISelectItems();
        uiSelectItems.setValue(listSelectItem);
        goToPageKtv.setValue(""+pageNum);
        goToPageKtv.getChildren().clear();
        goToPageKtv.getChildren().add(uiSelectItems);
        goToPageKtv.setValuePassThru(true);
        goToPageKtv.setAutoSubmit(true);
        Row currentRow = iterator.getCurrentRow();
        iterator.executeQuery();
        if (currentRow != null) {
            iterator.setCurrentRowWithKey(currentRow.getKey().toStringFormat(false));
        }
        if ((pageNum) * pageSize > rowCount) {
            iterator.setRangeSize(rowCount - (pageNum - 1) * pageSize);
        } else {
            iterator.setRangeSize(pageSize);
        }
        iterator.setRangeStart((pageNum - 1) * pageSize);

        AdfFacesContext.getCurrentInstance().addPartialTarget(firstPageKtv);
        AdfFacesContext.getCurrentInstance().addPartialTarget(prevPageKtv);
        AdfFacesContext.getCurrentInstance().addPartialTarget(nextPageKtv);
        AdfFacesContext.getCurrentInstance().addPartialTarget(lastPageKtv);
        AdfFacesContext.getCurrentInstance().addPartialTarget(goToPageKtv);
    }

    private void resetPagingKtv(String iteratorName) {
        DCIteratorBinding iterator = Utils.getIteratorBinding(iteratorName);
        int rowCount = (int)iterator.getEstimatedRowCount();
        int rowIndex = iterator.getCurrentRowIndexInRange() + 1;
        int pageSize = Utils.getPageSize("HtCauHinhView1Iterator");
        int pageCount = 1;
        int pageNum = 0;
        if (rowIndex % pageSize == 0) {
            pageNum = rowIndex / pageSize;
        } else {
            pageNum = rowIndex / pageSize + 1;
        }
        if (rowCount > pageSize) {
            if (rowCount % pageSize == 0) {
                pageCount = rowCount / pageSize;
            } else {
                pageCount = rowCount / pageSize + 1;
            }
        }

        if (pageNum < 1) {
            pageNum = 1;
        }
        if (pageNum > pageCount) {
            pageNum = pageCount;
        }
        if (pageNum == 1) {
            firstPageKtv.setDisabled(true);
            prevPageKtv.setDisabled(true);
        } else {
            firstPageKtv.setDisabled(false);
            prevPageKtv.setDisabled(false);
        }
        if (pageNum == pageCount) {
            lastPageKtv.setDisabled(true);
            nextPageKtv.setDisabled(true);
        } else {
            lastPageKtv.setDisabled(false);
            nextPageKtv.setDisabled(false);
        }
        int first = 1;
        if (pageNum < 5) {
            first = 1;
        } else if (pageNum + 9 > pageCount) {
            if (pageNum + 4 > pageCount) {
                if (pageCount - 6 < 1)
                    first = 1;
                else {
                    first = pageCount - 6;
                }
            } else {
                if (pageCount < 10) {
                    first = 1;
                } else {
                    first = pageNum - 4;
                }
            }
        } else {
            first = pageNum - 4;
        }
        List<SelectItem> listSelectItem = new ArrayList();

        for (int i = first, j = 0; i <= pageCount && j < 10; i++, j++) {
            SelectItem si = new SelectItem();
            si.setValue(""+i);
            si.setLabel(String.valueOf(i));
            listSelectItem.add(si);
        }
        UISelectItems uiSelectItems = new UISelectItems();
        uiSelectItems.setValue(listSelectItem);
        goToPageKtv.setValue(""+pageNum);
        goToPageKtv.getChildren().clear();
        goToPageKtv.getChildren().add(uiSelectItems);
        goToPageKtv.setValuePassThru(true);
        goToPageKtv.setAutoSubmit(true);
        Row currentRow = iterator.getCurrentRow();
        iterator.executeQuery();
        if (currentRow != null) {
            iterator.setCurrentRowWithKey(currentRow.getKey().toStringFormat(false));
        }
        if ((pageNum) * pageSize > rowCount) {
            iterator.setRangeSize(rowCount - (pageNum - 1) * pageSize);
        } else {
            iterator.setRangeSize(pageSize);
        }
        iterator.setRangeStart((pageNum - 1) * pageSize);

        AdfFacesContext.getCurrentInstance().addPartialTarget(firstPageKtv);
        AdfFacesContext.getCurrentInstance().addPartialTarget(prevPageKtv);
        AdfFacesContext.getCurrentInstance().addPartialTarget(nextPageKtv);
        AdfFacesContext.getCurrentInstance().addPartialTarget(lastPageKtv);
        AdfFacesContext.getCurrentInstance().addPartialTarget(goToPageKtv);
    }

    public void makeCurrent(SelectionEvent selectionEvent) {
        Map<String, Object> mapSelectedRow =
            (Map<String, Object>)tableVaoRaDonVi.getSelectedRowData();
        if (mapSelectedRow != null) {
            DCIteratorBinding ktvDvView1Iterator =
                Utils.getIteratorBinding("DlctKtvDvView1Iterator");
            ktvDvView1Iterator.setCurrentRowWithKey((String)mapSelectedRow.get(ROW_KEY));
        }
    }

    public void makeCurrentKtv(SelectionEvent selectionEvent) {
        Map<String, Object> mapSelectedRow =
            (Map<String, Object>)tableKtv.getSelectedRowData();
        if (mapSelectedRow != null) {
            DCIteratorBinding kiemToanVienView1Iterator =
                Utils.getIteratorBinding("DlctKiemToanVienView1Iterator");
            kiemToanVienView1Iterator.setCurrentRowWithKey((String)mapSelectedRow.get(ROW_KEY));
        }
    }

    public void showPopupThemMoi(ActionEvent actionEvent) {
        List<AdvancedSearchGroup> listASG = new ArrayList();
        AdvancedSearchGroup asg = new AdvancedSearchGroup();
        listASG.add(asg);
        AdvancedSearchItem asi = new AdvancedSearchItem();
        asg.getListChildren().add(asi);
        asi.setItemName("TrangThai");
        asi.setRequired(true);
        asi.getListValue().add(0,
                               new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
        Utils.searchadvanced("DlctKiemToanVienView1Iterator", listASG);
        Utils.searchadvanced("DlctKtvDvView1Iterator", new ArrayList());
        resetFormKtv();
        getValueKtv(0);
        DCIteratorBinding ktvDvView1Iterator =
            Utils.getIteratorBinding("DlctKtvDvView1Iterator");
        Row row =
            ktvDvView1Iterator.getViewObject().createAndInitRow(new NameValuePairs());
        ktvDvView1Iterator.executeQuery();
        ktvDvView1Iterator.setCurrentRowWithKey(row.getKey().toStringFormat(false));
        dialogUpdate.setTitle((String)Utils.getElExpression("#{adfBundle['view.ViewControllerBundle'].THEM_MOI}"));
        dialogUpdate.setAffirmativeTextAndAccessKey((String)Utils.getElExpression("#{adfBundle['view.ViewControllerBundle'].THEM_MOI}"));
        Utils.showPopup(popupUpdate);
    }

    public void showPopupSua(ActionEvent actionEvent) {
        if (tableVaoRaDonVi.getSelectedRowData() != null) {
            List<AdvancedSearchGroup> listASG = new ArrayList();
            AdvancedSearchGroup asg = new AdvancedSearchGroup();
            listASG.add(asg);
            AdvancedSearchItem asi = new AdvancedSearchItem();
            asg.getListChildren().add(asi);
            asi.setItemName("TrangThai");
            asi.setRequired(true);
            asi.getListValue().add(0,
                                   new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
            Utils.searchadvanced("DlctKiemToanVienView1Iterator", listASG);
            Utils.searchadvanced("DlctKtvDvView1Iterator", new ArrayList());
            DCIteratorBinding kiemToanVienView1Iterator =
                Utils.getIteratorBinding("DlctKiemToanVienView1Iterator");
            DCIteratorBinding ktvDvView1Iterator =
                Utils.getIteratorBinding("DlctKtvDvView1Iterator");
            Number kiemToanVienId =
                (Number)ktvDvView1Iterator.getCurrentRow().getAttribute("DlctKiemToanVienId");
            if (kiemToanVienId != null) {
                NameValuePairs nvp = new NameValuePairs();
                nvp.setAttribute("Id", new DBSequence(kiemToanVienId));
                Key rowKey =
                    kiemToanVienView1Iterator.getViewObject().createKey(nvp);
                kiemToanVienView1Iterator.setCurrentRowWithKey(rowKey.toStringFormat(false));
            }
            resetFormKtv();
            getValueKtv();
            dialogUpdate.setTitle((String)Utils.getElExpression("#{adfBundle['view.ViewControllerBundle'].CAP_NHAT}"));
            dialogUpdate.setAffirmativeTextAndAccessKey((String)Utils.getElExpression("#{adfBundle['view.ViewControllerBundle'].CAP_NHAT}"));
            Utils.showPopup(popupUpdate);
        }else{
            String errorString =
                Utils.getResourceBundle("CHON_BAN_GHI_DE_THAO_TAC");
            FacesContext.getCurrentInstance().addMessage(null,
                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                          errorString,
                                                                          errorString));
        }
    }

    public void showPopupXoa(ActionEvent actionEvent) {
        if (tableVaoRaDonVi.getSelectedRowData() != null) {
            Utils.showPopup(popupDelete);
        }else{
            String errorString =
                Utils.getResourceBundle("CHON_BAN_GHI_DE_THAO_TAC");
            FacesContext.getCurrentInstance().addMessage(null,
                                                         new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                          errorString,
                                                                          errorString));
        }
    }

    public void timKiem(ActionEvent actionEvent) {
        if (searchPanel.getChildren().size() > 0) {
            iteratorFilter();
            getValue(0);
            AdfFacesContext.getCurrentInstance().addPartialTarget(tableVaoRaDonVi);
            AdfFacesContext.getCurrentInstance().partialUpdateNotify(tableVaoRaDonVi);
        }
    }

    private void iteratorFilter() {
        if (searchPanel.getChildren().size() > 0) {
            {
                List<AdvancedSearchGroup> listASG = new ArrayList();
                AdvancedSearchGroup asg = new AdvancedSearchGroup();
                listASG.add(asg);
                AdvancedSearchItem asi = new AdvancedSearchItem();
                asg.getListChildren().add(asi);
                asi.setItemName("DlctLoaiTruongTt");
                asi.setRequired(true);
                asi.getListValue().add(0,
                                       new Number(Utils.ENUM_LOAI_TRUONG_TT.KIEM_TOAN_VIEN.getId()));
                asi = new AdvancedSearchItem();
                asg.getListChildren().add(asi);
                asi.setItemName("TrangThai");
                asi.setRequired(true);
                asi.getListValue().add(0,
                                       new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
                Utils.searchadvanced("DlctTruongTtView1Iterator", listASG);
            }
            DCIteratorBinding truongTtView1Iterator =
                Utils.getIteratorBinding("DlctTruongTtView1Iterator");
            List<UIComponent> listUIComponent = new ArrayList();
            List<UIComponent> listDetailItem = new ArrayList();
            List<UIComponent> listDetailItemNext = new ArrayList();
            listDetailItemNext.add(searchPanel);
            while (listDetailItemNext.size() > 0) {
                listDetailItem = listDetailItemNext;
                listDetailItemNext = new ArrayList();
                for (UIComponent loopComponent : listDetailItem) {
                    if (loopComponent != null) {
                        if (loopComponent instanceof RichPanelTabbed ||
                            loopComponent instanceof RichShowDetailItem ||
                            loopComponent instanceof RichPanelFormLayout) {
                            if (loopComponent.getChildCount() > 0) {
                                listDetailItemNext.addAll(loopComponent.getChildren());
                            }
                        }
                        if (loopComponent instanceof RichInputText ||
                            loopComponent instanceof RichInputDate) {
                            listUIComponent.add(loopComponent);
                        }
                    }
                }
            }
            List<AdvancedSearchGroup> listASG = new ArrayList();
            for (UIComponent ui : listUIComponent) {
                if (ui.getId() != null) {
                    String rowKey = ui.getId();
                    if (rowKey.startsWith(SEARCH_ID_PREFIX))
                        rowKey = rowKey.substring(SEARCH_ID_PREFIX.length());
                    truongTtView1Iterator.setCurrentRowWithKey(rowKey);
                    Row truongTtRow = truongTtView1Iterator.getCurrentRow();
                    if (truongTtRow != null) {
                    Row loopRow = truongTtRow;
                    Row rootRow = null;
                    while (loopRow != null) {
                        rootRow = loopRow;
                        loopRow =
                                (Row)loopRow.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                    }
                    Number id =
                        ((DBSequence)rootRow.getAttribute("Id")).getSequenceNumber();
                        Number kieuDuLieu =
                            (Number)truongTtRow.getAttribute("KieuDuLieu");
                        if (kieuDuLieu != null) {
                            int kieu = kieuDuLieu.intValue();
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        Number valNumber =
                                            new Number(valObject.toString().trim());
                                        AdvancedSearchGroup asgKtv =
                                            new AdvancedSearchGroup();
                                        listASG.add(asgKtv);
                                        AdvancedSearchItem asiKtv =
                                            new AdvancedSearchItem();
                                        asgKtv.getListChildren().add(asiKtv);
                                        asiKtv.setItemName("DlctKiemToanVienView");
                                        asiKtv.setRequired(true);
                                        asiKtv.setOperator(AdvancedSearchItem.OPER_EXISTS);

                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        asiKtv.getListChildren().add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValNumber");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valNumber);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = valObject.toString().trim();;
                                        valString = valString.toUpperCase();
                                        AdvancedSearchGroup asgKtv =
                                            new AdvancedSearchGroup();
                                        listASG.add(asgKtv);
                                        AdvancedSearchItem asiKtv =
                                            new AdvancedSearchItem();
                                        asgKtv.getListChildren().add(asiKtv);
                                        asiKtv.setItemName("DlctKiemToanVienView");
                                        asiKtv.setRequired(true);
                                        asiKtv.setOperator(AdvancedSearchItem.OPER_EXISTS);

                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        asiKtv.getListChildren().add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValVarchar");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = valObject.toString().trim();;
                                        valString = valString.toUpperCase();
                                        AdvancedSearchGroup asgKtv =
                                            new AdvancedSearchGroup();
                                        listASG.add(asgKtv);
                                        AdvancedSearchItem asiKtv =
                                            new AdvancedSearchItem();
                                        asgKtv.getListChildren().add(asiKtv);
                                        asiKtv.setItemName("DlctKiemToanVienView");
                                        asiKtv.setRequired(true);
                                        asiKtv.setOperator(AdvancedSearchItem.OPER_EXISTS);

                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        asiKtv.getListChildren().add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValVarchar");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = valObject.toString().trim();;
                                        valString = valString.toUpperCase();
                                        AdvancedSearchGroup asgKtv =
                                            new AdvancedSearchGroup();
                                        listASG.add(asgKtv);
                                        AdvancedSearchItem asiKtv =
                                            new AdvancedSearchItem();
                                        asgKtv.getListChildren().add(asiKtv);
                                        asiKtv.setItemName("DlctKiemToanVienView");
                                        asiKtv.setRequired(true);
                                        asiKtv.setOperator(AdvancedSearchItem.OPER_EXISTS);

                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        asiKtv.getListChildren().add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValVarchar");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                RichInputDate inputDate = (RichInputDate)ui;
                                Object valObject = inputDate.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        java.util.Date javaDate =
                                            (java.util.Date)valObject;
                                        Timestamp timestamp =
                                            new Timestamp(javaDate.getTime());
                                        oracle.jbo.domain.Date valDate =
                                            new oracle.jbo.domain.Date(timestamp);
                                        AdvancedSearchGroup asgKtv =
                                            new AdvancedSearchGroup();
                                        listASG.add(asgKtv);
                                        AdvancedSearchItem asiKtv =
                                            new AdvancedSearchItem();
                                        asgKtv.getListChildren().add(asiKtv);
                                        asiKtv.setItemName("DlctKiemToanVienView");
                                        asiKtv.setRequired(true);
                                        asiKtv.setOperator(AdvancedSearchItem.OPER_EXISTS);

                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        asiKtv.getListChildren().add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValDate");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valDate);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = (String)valObject;
                                        valString = valString.toUpperCase();
                                        AdvancedSearchGroup asgKtv =
                                            new AdvancedSearchGroup();
                                        listASG.add(asgKtv);
                                        AdvancedSearchItem asiKtv =
                                            new AdvancedSearchItem();
                                        asgKtv.getListChildren().add(asiKtv);
                                        asiKtv.setItemName("DlctKiemToanVienView");
                                        asiKtv.setRequired(true);
                                        asiKtv.setOperator(AdvancedSearchItem.OPER_EXISTS);

                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        asiKtv.getListChildren().add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValClob");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = (String)valObject;
                                        valString = valString.toUpperCase();
                                        AdvancedSearchGroup asgKtv =
                                            new AdvancedSearchGroup();
                                        listASG.add(asgKtv);
                                        AdvancedSearchItem asiKtv =
                                            new AdvancedSearchItem();
                                        asgKtv.getListChildren().add(asiKtv);
                                        asiKtv.setItemName("DlctKiemToanVienView");
                                        asiKtv.setRequired(true);
                                        asiKtv.setOperator(AdvancedSearchItem.OPER_EXISTS);

                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        asiKtv.getListChildren().add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("HtFileView");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        asiChild.setRequired(true);

                                        AdvancedSearchGroup asgFile =
                                            new AdvancedSearchGroup();
                                        asiChild.getListChildren().add(asgFile);
                                        AdvancedSearchItem asiFile =
                                            new AdvancedSearchItem();
                                        asgFile.getListChildren().add(asiFile);
                                        asiFile.setItemName("TenFile");
                                        asiFile.setRequired(true);
                                        asiFile.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Utils.searchadvanced("DlctKtvDvView1Iterator", listASG);
        }
    }

    public void timKiemKtv(ActionEvent actionEvent) {
        if (searchKtvPanel.getChildren().size() > 0) {
            iteratorFilterKtv();
            getValueKtv(0);
            AdfFacesContext.getCurrentInstance().addPartialTarget(tableKtv);
            AdfFacesContext.getCurrentInstance().partialUpdateNotify(tableKtv);
        }
    }

    private void iteratorFilterKtv() {
        if (searchKtvPanel.getChildren().size() > 0) {
            DCIteratorBinding truongTtView1Iterator =
                Utils.getIteratorBinding("DlctTruongTtView1Iterator");
            List<UIComponent> listUIComponent = new ArrayList();
            List<UIComponent> listDetailItem = new ArrayList();
            List<UIComponent> listDetailItemNext = new ArrayList();
            listDetailItemNext.add(searchKtvPanel);
            while (listDetailItemNext.size() > 0) {
                listDetailItem = listDetailItemNext;
                listDetailItemNext = new ArrayList();
                for (UIComponent loopComponent : listDetailItem) {
                    if (loopComponent != null) {
                        if (loopComponent instanceof RichPanelTabbed ||
                            loopComponent instanceof RichShowDetailItem ||
                            loopComponent instanceof RichPanelFormLayout) {
                            if (loopComponent.getChildCount() > 0) {
                                listDetailItemNext.addAll(loopComponent.getChildren());
                            }
                        }
                        if (loopComponent instanceof RichInputText ||
                            loopComponent instanceof RichInputDate) {
                            listUIComponent.add(loopComponent);
                        }
                    }
                }
            }
            List<AdvancedSearchGroup> listASG = new ArrayList();
            AdvancedSearchGroup asgTrangThai =
                new AdvancedSearchGroup();
            listASG.add(asgTrangThai);
            AdvancedSearchItem asiTrangThai =
                new AdvancedSearchItem();
            asgTrangThai.getListChildren().add(asiTrangThai);
            asiTrangThai.setItemName("TrangThai");
            asiTrangThai.setRequired(true);
            asiTrangThai.getListValue().add(0,
                                            new Number(Utils.ENUM_TRANG_THAI.CONG_BO.getId()));
            for (UIComponent ui : listUIComponent) {
                if (ui.getId() != null) {
                    String rowKey = ui.getId();
                    if (rowKey.startsWith(SEARCH_KTV_ID_PREFIX))
                        rowKey =
                                rowKey.substring(SEARCH_KTV_ID_PREFIX.length());
                    truongTtView1Iterator.setCurrentRowWithKey(rowKey);
                    Row truongTtRow = truongTtView1Iterator.getCurrentRow();
                    if (truongTtRow != null) {
                    Row loopRow = truongTtRow;
                    Row rootRow = null;
                    while (loopRow != null) {
                        rootRow = loopRow;
                        loopRow =
                                (Row)loopRow.getAttribute("DlctTruongTtTuIdDlctTruongTtView");
                    }
                    Number id =
                        ((DBSequence)rootRow.getAttribute("Id")).getSequenceNumber();
                        Number kieuDuLieu =
                            (Number)truongTtRow.getAttribute("KieuDuLieu");
                        if (kieuDuLieu != null) {
                            int kieu = kieuDuLieu.intValue();
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        Number valNumber =
                                            new Number(valObject.toString().trim());
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValNumber");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valNumber);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = valObject.toString().trim();
                                        valString = valString.toUpperCase();
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValVarchar");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = valObject.toString().trim();
                                        valString = valString.toUpperCase();
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValVarchar");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu ==
                                Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = valObject.toString().trim();
                                        valString = valString.toUpperCase();
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValVarchar");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
                                RichInputDate inputDate = (RichInputDate)ui;
                                Object valObject = inputDate.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        java.util.Date javaDate =
                                            (java.util.Date)valObject;
                                        Timestamp timestamp =
                                            new Timestamp(javaDate.getTime());
                                        oracle.jbo.domain.Date valDate =
                                            new oracle.jbo.domain.Date(timestamp);
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValDate");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valDate);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = (String)valObject;
                                        valString = valString.toUpperCase();
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("ValClob");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_CONTAINS);
                                        asiChild.setUpperColumns(true);
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                            if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
                                RichInputText inputText = (RichInputText)ui;
                                Object valObject = inputText.getValue();
                                if (valObject != null &&
                                    valObject.toString().isEmpty() == false) {
                                    try {
                                        String valString = (String)valObject;
                                        valString = valString.toUpperCase();
                                        AdvancedSearchGroup asg =
                                            new AdvancedSearchGroup();
                                        listASG.add(asg);
                                        AdvancedSearchItem asi =
                                            new AdvancedSearchItem();
                                        asg.getListChildren().add(asi);
                                        asi.setItemName("DlctGtKtvTtView");
                                        asi.setRequired(true);
                                        asi.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        AdvancedSearchGroup asgChild =
                                            new AdvancedSearchGroup();
                                        asgChild.setConjunction(AdvancedSearchGroup.VC_CONJ_OR);
                                        asi.getListChildren().add(asgChild);
                                        AdvancedSearchItem asiChild =
                                            new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("DlctTruongTtId");
                                        asiChild.setRequired(true);
                                        asiChild.getListValue().add(id);
                                        asiChild = new AdvancedSearchItem();
                                        asgChild.getListChildren().add(asiChild);
                                        asiChild.setItemName("HtFileView");
                                        asiChild.setOperator(AdvancedSearchItem.OPER_EXISTS);
                                        asiChild.setRequired(true);

                                        AdvancedSearchGroup asgFile =
                                            new AdvancedSearchGroup();
                                        asiChild.getListChildren().add(asgFile);
                                        AdvancedSearchItem asiFile =
                                            new AdvancedSearchItem();
                                        asgFile.getListChildren().add(asiFile);
                                        asiFile.setItemName("TenFile");
                                        asiFile.setRequired(true);
                                        asiFile.getListValue().add(valString);
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                        String errorString =
                                            Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
                                        FacesContext.getCurrentInstance().addMessage(ui.getClientId(FacesContext.getCurrentInstance()),
                                                                                     new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                                                      errorString,
                                                                                                      errorString));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            Utils.searchadvanced("DlctKiemToanVienView1Iterator", listASG);
        }
    }

    public void firstPage(ActionEvent actionEvent) {
        getValue(1);
    }

    public void prevPage(ActionEvent actionEvent) {
        Integer integer = null;
        try {
            integer = new Integer(goToPage.getValue().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (integer != null) {
            getValue(integer.intValue() - 1);
        }
    }

    public void nextPage(ActionEvent actionEvent) {
        Integer integer = null;
        try {
            integer = new Integer(goToPage.getValue().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (integer != null) {
            getValue(integer.intValue() + 1);
        }
    }

    public void lastPage(ActionEvent actionEvent) {
        getValueKtv(999999);
    }

    public void firstPageKtv(ActionEvent actionEvent) {
        getValueKtv(1);
    }

    public void prevPageKtv(ActionEvent actionEvent) {
        Integer integer = null;
        try {
            integer = new Integer(goToPageKtv.getValue().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (integer != null) {
            getValueKtv(integer.intValue() - 1);
        }
    }

    public void nextPageKtv(ActionEvent actionEvent) {
        Integer integer = null;
        try {
            integer = new Integer(goToPageKtv.getValue().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (integer != null) {
            getValueKtv(integer.intValue() + 1);
        }
    }

    public void lastPageKtv(ActionEvent actionEvent) {
        getValueKtv(999999);
    }

    public void changePage(ValueChangeEvent valueChangeEvent) {
        if (valueChangeEvent.getNewValue() != null) {
            if (valueChangeEvent.getOldValue() != null &&
                valueChangeEvent.getNewValue().toString().equals(valueChangeEvent.getOldValue().toString())) {
                return;
            }
            Integer integer = null;
            try {
                integer =
                        new Integer(valueChangeEvent.getNewValue().toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (integer != null) {
                getValue(integer.intValue());
            }
        }
    }

    public void changePageKtv(ValueChangeEvent valueChangeEvent) {
        if (valueChangeEvent.getNewValue() != null) {
            if (valueChangeEvent.getOldValue() != null &&
                valueChangeEvent.getNewValue().toString().equals(valueChangeEvent.getOldValue().toString())) {
                return;
            }
            Integer integer = null;
            try {
                integer =
                        new Integer(valueChangeEvent.getNewValue().toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (integer != null) {
                getValueKtv(integer.intValue());
            }
        }
    }

    public void rollback(PopupCanceledEvent popupCanceledEvent) {
        DCIteratorBinding donViView1Iterator =
            Utils.getIteratorBinding("DlctDonViView1Iterator");
        String rowKey = null;
        if (donViView1Iterator.getCurrentRow() != null)
            rowKey =
                    donViView1Iterator.getCurrentRow().getKey().toStringFormat(false);
        donViView1Iterator.getDataControl().getApplicationModule().getTransaction().rollback();
                iteratorFilter();
        if (rowKey != null)
            donViView1Iterator.setCurrentRowWithKey(rowKey);
        DCIteratorBinding ktvDvView1Iterator =
            Utils.getIteratorBinding("DlctKtvDvView1Iterator");

        rowKey = null;
        if (ktvDvView1Iterator.getCurrentRow() != null)
            rowKey =
                    ktvDvView1Iterator.getCurrentRow().getKey().toStringFormat(false);
        iteratorFilter();
        if (rowKey != null)
            ktvDvView1Iterator.setCurrentRowWithKey(rowKey);
        Integer pageNum = null;
        try {
            pageNum = new Integer(goToPage.getValue().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (pageNum != null) {
            getValue(pageNum.intValue());
        }
    }

    public void commit(DialogEvent dialogEvent) {
        DCIteratorBinding kiemToanVienView1Iterator =
            Utils.getIteratorBinding("DlctKiemToanVienView1Iterator");
        DCIteratorBinding ktvDvView1Iterator =
            Utils.getIteratorBinding("DlctKtvDvView1Iterator");
        RowSet rowSetKtvDv =
            (RowSet)kiemToanVienView1Iterator.getCurrentRow().getAttribute("DlctKtvDvView");
        boolean error = false;
        Row rowUpdate = null;
        oracle.jbo.domain.Date ngayBatDau =
            (oracle.jbo.domain.Date)ktvDvView1Iterator.getCurrentRow().getAttribute("NgayBatDau");
        oracle.jbo.domain.Date ngayKetThuc =
            (oracle.jbo.domain.Date)ktvDvView1Iterator.getCurrentRow().getAttribute("NgayKetThuc");
        String rowKey =
            ktvDvView1Iterator.getCurrentRow().getKey().toStringFormat(false);
        if (ngayKetThuc != null &&
            ngayBatDau.dateValue().after(ngayKetThuc.dateValue())) {
            String errorString =
                Utils.getResourceBundle("NGAY_BAT_DAU_SAU_NGAY_KET_THUC");
            Utils.showMessage(dialogEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                              Utils.MSG_ERROR, errorString, errorString);
            return;
        }
        if (rowSetKtvDv != null) {
            rowSetKtvDv.setRangeSize(-1);
            Row[] rowsKtvDv = rowSetKtvDv.getAllRowsInRange();
            if (rowsKtvDv != null) {
                for (Row rowKtvDv : rowsKtvDv) {
                    oracle.jbo.domain.Date ngayBatDauLoop =
                        (oracle.jbo.domain.Date)rowKtvDv.getAttribute("NgayBatDau");
                    oracle.jbo.domain.Date ngayKetThucLoop =
                        (oracle.jbo.domain.Date)rowKtvDv.getAttribute("NgayKetThuc");
                    String rowKeyLoop =
                        rowKtvDv.getKey().toStringFormat(false);
                    if (rowKey.equals(rowKeyLoop)) {
                        continue;
                    }
                    if (ngayKetThucLoop == null) {
                        if (ngayBatDau.dateValue().after(ngayBatDauLoop.dateValue())) {
                            if (rowUpdate == null) {
                                rowUpdate = rowKtvDv;
                            } else {
                                error = true;
                                break;
                            }
                        } else if (ngayKetThuc != null &&
                                   ngayKetThuc.dateValue().before(ngayBatDauLoop.dateValue())) {
                            //ok
                        } else {
                            error = true;
                            break;
                        }
                    } else {
                        if (ngayKetThucLoop.dateValue().before(ngayBatDau.dateValue())) {
                            //ok
                        } else {
                            if (ngayKetThuc != null &&
                                ngayKetThuc.dateValue().before(ngayBatDauLoop.dateValue())) {
                                //ok
                            } else {
                                error = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (error == false) {
            if (rowUpdate != null) {
                rowUpdate.setAttribute("NgayKetThuc",
                                       ktvDvView1Iterator.getCurrentRow().getAttribute("NgayBatDau"));
            }
            ktvDvView1Iterator.getCurrentRow().setAttribute("DlctKiemToanVienId",
                                                            ((DBSequence)kiemToanVienView1Iterator.getCurrentRow().getAttribute("Id")).getSequenceNumber());
            ktvDvView1Iterator.getDataControl().getApplicationModule().getTransaction().commit();
            String currentRowKey =
                ktvDvView1Iterator.getCurrentRow().getKey().toStringFormat(false);
            iteratorFilter();
            ktvDvView1Iterator.setRangeSize(-1);
            ktvDvView1Iterator.setCurrentRowWithKey(currentRowKey);
            int pageSize = Utils.getPageSize("HtCauHinhView1Iterator");
            int rowIndex = ktvDvView1Iterator.getCurrentRowIndexInRange();
            int pageNum = 0;
            if (rowIndex % pageSize == 0) {
                pageNum = rowIndex / pageSize + 1;
            } else {
                pageNum = rowIndex / pageSize + 1;
            }
            getValue(pageNum);
        } else {
            String errorString =
                Utils.getResourceBundle("GIA_TRI_KHONG_HOP_LE");
            Utils.showMessage(dialogEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                              Utils.MSG_ERROR, errorString, errorString);
            return;
        }
    }

    public void delete(DialogEvent dialogEvent) {
        try {
            DCIteratorBinding ktvDvView1Iterator =
                Utils.getIteratorBinding("DlctKtvDvView1Iterator");
            ktvDvView1Iterator.removeCurrentRow();
            ktvDvView1Iterator.getDataControl().getApplicationModule().getTransaction().commit();

            iteratorFilter();
            Integer pageNum = null;
            try {
                pageNum = new Integer(goToPage.getValue().toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (pageNum != null) {
                getValue(pageNum.intValue());
            }
        } catch (Exception e) {
                String errorString =
                    Utils.getResourceBundle("CON_BAN_GHI_LIEN_QUAN");
                FacesContext.getCurrentInstance().addMessage(dialogEvent.getComponent().getClientId(FacesContext.getCurrentInstance()),
                                                             new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                                                              errorString,
                                                                              errorString));
            e.printStackTrace();
        }
    }

    private List<UIComponent> createSearchComponent(String id, String ten,
                                                    int kieu) {
        List<UIComponent> result = new ArrayList();
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.NUMBER.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.VARCHAR.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.LINK.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.EMAIL.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
            DateTimeConverter converter = (DateTimeConverter)FacesContext.getCurrentInstance().getApplication()
            .createConverter("javax.faces.DateTime");
            converter.setLocale(new Locale(DEFAULT_LANGCODE));
            converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
            converter.setType("date");
            converter.setDateStyle("short");
            RichInputDate inputDate = new RichInputDate();
            inputDate.setConverter(converter);
            inputDate.setId(id);
            inputDate.setLabel(ten);
            inputDate.setAutoSubmit(true);
            result.add(inputDate);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.CLOB.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.FILE.getId()) {
            RichInputText inputText = new RichInputText();
            inputText.setId(id);
            inputText.setLabel(ten);
            inputText.setContentStyle("width:300px;");
            inputText.setAutoSubmit(true);
            result.add(inputText);
        }
        return result;
    }

    private UIComponent createColumn(String id, String ten,int kieu) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application app = fc.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = fc.getELContext();
        ValueExpression valueExp;
        RichColumn column = new RichColumn();
        column.setHeaderText(ten);
        RichOutputText outputText = new RichOutputText();
        valueExp =
                elFactory.createValueExpression(elContext, "#{row['" + id + "']}",
                                                Object.class);
        outputText.setValueExpression("value", valueExp);
        if (kieu == Utils.ENUM_KIEU_DU_LIEU.DATE.getId()) {
            DateTimeConverter converter = (DateTimeConverter)FacesContext.getCurrentInstance().getApplication()
            .createConverter("javax.faces.DateTime");
            converter.setLocale(new Locale(DEFAULT_LANGCODE));
            converter.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));
            converter.setType("date");
            converter.setDateStyle("short");
            outputText.setConverter(converter);
        }
        column.getChildren().add(outputText);
        return column;
    }
    
    public Locale getLocale(){
        return new Locale(DEFAULT_LANGCODE);
    }
    
    public TimeZone getTimeZone(){
        return TimeZone.getTimeZone("GMT+7:00");
    }

    public void setSearchPanel(RichPanelFormLayout searchPanel) {
        this.searchPanel = searchPanel;
    }

    public RichPanelFormLayout getSearchPanel() {
        return searchPanel;
    }

    public void setGoToPage(RichSelectOneChoice goToPage) {
        this.goToPage = goToPage;
    }

    public RichSelectOneChoice getGoToPage() {
        return goToPage;
    }

    public void setPopupUpdate(RichPopup popupUpdate) {
        this.popupUpdate = popupUpdate;
    }

    public RichPopup getPopupUpdate() {
        return popupUpdate;
    }

    public void setDialogUpdate(RichDialog dialogUpdate) {
        this.dialogUpdate = dialogUpdate;
    }

    public RichDialog getDialogUpdate() {
        return dialogUpdate;
    }

    public void setPopupDelete(RichPopup popupDelete) {
        this.popupDelete = popupDelete;
    }

    public RichPopup getPopupDelete() {
        return popupDelete;
    }

    public void setUpdatePanel(RichPanelTabbed updatePanel) {
        this.updatePanel = updatePanel;
    }

    public RichPanelTabbed getUpdatePanel() {
        return updatePanel;
    }

    public void setFirstPage(RichCommandToolbarButton firstPage) {
        this.firstPage = firstPage;
    }

    public RichCommandToolbarButton getFirstPage() {
        return firstPage;
    }

    public void setPrevPage(RichCommandToolbarButton prevPage) {
        this.prevPage = prevPage;
    }

    public RichCommandToolbarButton getPrevPage() {
        return prevPage;
    }

    public void setNextPage(RichCommandToolbarButton nextPage) {
        this.nextPage = nextPage;
    }

    public RichCommandToolbarButton getNextPage() {
        return nextPage;
    }

    public void setLastPage(RichCommandToolbarButton lastPage) {
        this.lastPage = lastPage;
    }

    public RichCommandToolbarButton getLastPage() {
        return lastPage;
    }

    public void setSearchKtvPanel(RichPanelFormLayout searchKtvPanel) {
        this.searchKtvPanel = searchKtvPanel;
    }

    public RichPanelFormLayout getSearchKtvPanel() {
        return searchKtvPanel;
    }

    public void setTableVaoRaDonVi(RichTable tableVaoRaDonVi) {
        this.tableVaoRaDonVi = tableVaoRaDonVi;
    }

    public RichTable getTableVaoRaDonVi() {
        return tableVaoRaDonVi;
    }

    public void setTableKtv(RichTable tableKtv) {
        this.tableKtv = tableKtv;
    }

    public RichTable getTableKtv() {
        return tableKtv;
    }

    public void setGoToPageKtv(RichSelectOneChoice goToPageKtv) {
        this.goToPageKtv = goToPageKtv;
    }

    public RichSelectOneChoice getGoToPageKtv() {
        return goToPageKtv;
    }

    public void setFirstPageKtv(RichCommandToolbarButton firstPageKtv) {
        this.firstPageKtv = firstPageKtv;
    }

    public RichCommandToolbarButton getFirstPageKtv() {
        return firstPageKtv;
    }

    public void setPrevPageKtv(RichCommandToolbarButton prevPageKtv) {
        this.prevPageKtv = prevPageKtv;
    }

    public RichCommandToolbarButton getPrevPageKtv() {
        return prevPageKtv;
    }

    public void setNextPageKtv(RichCommandToolbarButton nextPageKtv) {
        this.nextPageKtv = nextPageKtv;
    }

    public RichCommandToolbarButton getNextPageKtv() {
        return nextPageKtv;
    }

    public void setLastPageKtv(RichCommandToolbarButton lastPageKtv) {
        this.lastPageKtv = lastPageKtv;
    }

    public RichCommandToolbarButton getLastPageKtv() {
        return lastPageKtv;
    }

    public void setTenDonVi(RichOutputText tenDonVi) {
        this.tenDonVi = tenDonVi;
    }

    public RichOutputText getTenDonVi() {
        return tenDonVi;
    }
}
